//
// Created by hp on 2017/6/16.
//

#include <jni.h>

#include <android/log.h>


#ifndef LOG_TAG

#define LOG_TAG"ANDROID_LAB"

#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)

#endif


JNIEXPORT jint JNICALL Java_com_ycsd_monthly_BsPatch_applyBsPatch(JNIEnv *env, jclass clazz, jstring oldPath, jstring newPath, jstring patchPath){

    LOGE("log string from ndk.");

    int ret = -1;

    int argc = 4;
    char * argv[4];

    argv[0] = "com_ycsd_monthly_BsPatch_bsPatch";

    char * oldPathStr = (*env) ->GetStringUTFChars(env, oldPath, JNI_FALSE);
    char * newPathStr = (*env) ->GetStringUTFChars(env, newPath, JNI_FALSE);
    char * patchPathStr = (*env) ->GetStringUTFChars(env, patchPath, JNI_FALSE);

    argv[1] = oldPathStr;
    argv[2] = newPathStr;
    argv[3] = patchPathStr;

    LOGD("bsPatch begin");

    ret = bsPatch(argc, argv);

    if(ret < 0) {
        LOGD("bspatch error");
    } else{
        LOGD("bspatch success");
    }

    return ret;

}
